import 'dart:convert';

//工具信息
class ToolData {
  String id;
  String imgUrl;
  String toolName;
  String toolSpec;
  String epc;
  String toolCode;
  String storageSerialNo;
  int state;
  String lockerPosition;
  String lockerSerialNo;
  String factoryNum;
  ToolData({
    required this.id,
    required this.imgUrl,
    required this.toolName,
    required this.toolSpec,
    required this.epc,
    required this.toolCode,
    required this.storageSerialNo,
    required this.state,
    required this.lockerPosition,
    required this.lockerSerialNo,
    required this.factoryNum
  });


  // static List<ToolData> toolList = <ToolData>[
  //   ToolData(
  //       id: '1',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "1321312312",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 1,
  //       info: "备注"),
  //   ToolData(
  //       id: '2',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "534534534534",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 0,
  //       info: "备注"),
  //   ToolData(
  //       id: '3',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "124689900",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 1,
  //       info: "备注"),
  //   ToolData(
  //       id: '4',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "-98776w",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 0,
  //       info: "备注"),
  //   ToolData(
  //       id: '5',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "348905rwvfdvfd",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 1,
  //       info: "备注"),
  //   ToolData(
  //       id: '6',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "123kllkj",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 0,
  //       info: "备注"),
  //   ToolData(
  //       id: '7',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "sdfds131312",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 1,
  //       info: "备注"),
  //   ToolData(
  //       id: '8',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "45345345fhgf",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 0,
  //       info: "备注"),
  //   ToolData(
  //       id: '9',
  //       imgUrl:
  //           "https://img0.baidu.com/it/u=333829888,1801926669&fm=253&fmt=auto?w=722&h=500",
  //       name: "测试工具",
  //       spec: "16*9",
  //       epc: "32157987sfds",
  //       serialNum: "Ser-1232",
  //       storageId: 1,
  //       state: 1,
  //       info: "备注")
  // ];


  ToolData copyWith({
    String? id,
    String? imgUrl,
    String? toolName,
    String? toolSpec,
    String? epc,
    String? toolCode,
    String? storageSerialNo,
    int? state,
    String? lockerPosition,
    String? lockerSerialNo,
    String? factoryNum
  }) {
    return ToolData(
      id: id ?? this.id,
      imgUrl: imgUrl ?? this.imgUrl,
      toolName: toolName ?? this.toolName,
      toolSpec: toolSpec ?? this.toolSpec,
      epc: epc ?? this.epc,
      toolCode: toolCode ?? this.toolCode,
      storageSerialNo: storageSerialNo ?? this.storageSerialNo,
      state: state ?? this.state,
      lockerPosition: lockerPosition ?? this.lockerPosition,
      lockerSerialNo: lockerSerialNo ?? this.lockerSerialNo,
      factoryNum: factoryNum??this.factoryNum
    );
  }

  Map<String, dynamic> toMap() {
    final result = <String, dynamic>{};
  
    result.addAll({'id': id});
    result.addAll({'imgUrl': imgUrl});
    result.addAll({'toolName': toolName});
    result.addAll({'toolSpec': toolSpec});
    result.addAll({'epc': epc});
    result.addAll({'toolCode': toolCode});
    result.addAll({'storageSerialNo': storageSerialNo});
    result.addAll({'state': state});
    result.addAll({'lockerPosition': lockerPosition});
    result.addAll({'lockerSerialNo': lockerSerialNo});
    result.addAll({'factoryNum':factoryNum});
  
    return result;
  }

  factory ToolData.fromMap(Map<String, dynamic> map) {
    return ToolData(
      id: map['id'] ?? '',
      imgUrl: map['imgUrl'] ?? '',
      toolName: map['toolName'] ?? '',
      toolSpec: map['toolSpec'] ?? '',
      epc: map['epc'] ?? '',
      toolCode: map['toolCode'] ?? '',
      storageSerialNo: map['storageSerialNo'] ?? '',
      state: map['state']?.toInt() ?? 0,
      lockerPosition: map['lockerPosition'] ?? '',
      lockerSerialNo: map['lockerSerialNo'] ?? '',
      factoryNum: map['factoryNum']??''
    );
  }

  String toJson() => json.encode(toMap());

  factory ToolData.fromJson(String source) => ToolData.fromMap(json.decode(source));

  @override
  String toString() {
    return 'ToolData(id: $id, imgUrl: $imgUrl, toolName: $toolName, toolSpec: $toolSpec, epc: $epc, toolCode: $toolCode, storageSerialNo: $storageSerialNo, state: $state, lockerPosition: $lockerPosition, lockerSerialNo: $lockerSerialNo)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
  
    return other is ToolData &&
      other.id == id &&
      other.imgUrl == imgUrl &&
      other.toolName == toolName &&
      other.toolSpec == toolSpec &&
      other.epc == epc &&
      other.toolCode == toolCode &&
      other.storageSerialNo == storageSerialNo &&
      other.state == state &&
      other.lockerPosition == lockerPosition &&
      other.lockerSerialNo == lockerSerialNo&&other.factoryNum==factoryNum;
  }

  @override
  int get hashCode {
    return id.hashCode ^
      imgUrl.hashCode ^
      toolName.hashCode ^
      toolSpec.hashCode ^
      epc.hashCode ^
      toolCode.hashCode ^
      storageSerialNo.hashCode ^
      state.hashCode ^
      lockerPosition.hashCode ^
      lockerSerialNo.hashCode;
  }
}
